package cn.ycc1.boot3rabbitmq.service.mq;

import org.springframework.amqp.core.*;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.stereotype.Component;

/**
 * @author ycc
 * @date 2024/10/29
 */
@Configuration
public class TestRabbitConfig {
    @Bean
    Queue queue() {
        return QueueBuilder.durable("myQueue").build();
    }

    @Bean
    @ConditionalOnMissingBean(name = "testExchange")
    Exchange testExchange() {
        return ExchangeBuilder.directExchange("myExchange")
                .durable(true)
//                .delayed()
                .build();
    }

    //    @Bean
//    Binding binding(Queue queue, DirectExchange exchange) {
//        return BindingBuilder.bind(queue).to(exchange).with("routingKey");
//    }
    @Bean
    Binding binding() {
        return BindingBuilder.bind(queue()).to(testExchange()).with("testRoutingKey").noargs();
    }
}
